package controllers;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import model.CaseGoods;
import model.Case_goods_img;
import model.Goods_antique;
import model.Goods_car;
import model.Goods_cash;
import model.Goods_immovable;
import model.Goods_ordinaty;
import model.Goods_video;
import model.User_list;

import com.et.mvc.JsonView;
import com.et.mvc.MultipartFile;
import com.wzzz.cache.CompanyCacheHandler;
import com.wzzz.util.SysDate;

public class CasePropertyManagerController extends ApplicationController {

	public JsonView getCaseGoods(int rows, int page) throws Exception {
		String cond = "1=1 and keep_status=0";
		List<Object> tmpArgs = new ArrayList<Object>();
		Object[] args = tmpArgs.toArray();
		String type = request.getParameter("type");
		List<CaseGoods> units = new ArrayList<CaseGoods>();
		long total = 0;
		// 在这里判断type，不过应该可以不用type，可以测试一下，第一次输入查询条件，然后把查询条件删除掉，看看会不会有bug，有bug晚上再搞定
		if (type == null) {
			total = CaseGoods.count(CaseGoods.class, cond, args);
			units = CaseGoods.findAll(CaseGoods.class, cond, args, "GOODS_ID",
					rows, (page - 1) * rows);
		} else {

			StringBuilder condition = new StringBuilder();
			condition.append("1=1 and keep_status=0");
			// 在这里获取所有补齐的请求得参数
			String ajbh = request.getParameter("AJBH");
			// buildCondition方法是封装得，参数说明见方法
				buildCondition(condition, "%" + ajbh + "%", "CASE_NUM", "like");
			String ajmc = request.getParameter("AJMC");
				buildCondition(condition, "%" + ajmc + "%", "CASE_NAME", "like");
			String wpsbdw = request.getParameter("WPSBDW");//物品上报单位
				buildCondition(condition,"%"+wpsbdw+"%","GOODS_COMPANY","like");
			String wpsbr = request.getParameter("WPSBR");  //物品上报人
				buildCondition(condition,"%"+wpsbr+"%","CASE_TO_MAN","like");
			String sbsj = request.getParameter("SBSJ");   //上报时间
				buildCondition(condition,"%"+sbsj+"%","SAVE_DATE","like");
			String ajlb = request.getParameter("AJLB");//案件类别
				buildCondition(condition,"%"+ajlb+"%","CASE_TYPE","like");
			
			total = CaseGoods.count(CaseGoods.class, condition.toString(), args);
			units = CaseGoods.findAll(CaseGoods.class, condition.toString(),args, "GOODS_ID", rows, (page - 1) * rows);
		}

		// 构造JSON用的数据结构并返回JSON视图
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("total", total);
		result.put("rows", units);
		return new JsonView(result);
	}

	public JsonView getUnit(int id) throws Exception {
		CaseGoods unit = CaseGoods.find(CaseGoods.class, id);
		return new JsonView(unit);
	}

	/**
	 * 构造查询条件得方法
	 * 
	 * @param cond
	 *            查询条件，第一次是 1=1 ，然后不停得拼接 and条件
	 * @param value
	 *            查询得值，如果是like查询，需要手动加'%' %value%
	 * @param target
	 *            目标字段
	 * @param operate
	 *            操作符
	 */
	private void buildCondition(StringBuilder cond, String value,
			String target, String operate) {
		if (value != null && !"".equals(value) && value.replaceAll("%","").length() > 0) {
			cond.append(" and ").append(target).append(" ").append(operate)
					.append(" '").append(value).append("'");
		}
	}

	public JsonView searchCaseGoods(int rows, int page) throws Exception {
		String type = request.getParameter("type");
		StringBuilder cond = new StringBuilder();
		cond.append("1=1 and keep_status=0");
		// if(type!=null && type.equals("search")){
		String ajbh = request.getParameter("AJBH");
		buildCondition(cond, "%" + ajbh + "%", "CASE_NUM", "like");
		String ajlb = request.getParameter("AJLB");
		String ajmc = request.getParameter("AJMC");
		String wpsbdw = request.getParameter("WPSBDW");
		String wpsbr = request.getParameter("WPSBR");
		String sbsj = request.getParameter("SBSJ");
		// }
		List<Object> tmpArgs = new ArrayList<Object>();
		Object[] args = tmpArgs.toArray();
		List<CaseGoods> units = CaseGoods.findAll(CaseGoods.class,
				cond.toString(), args, "GOODS_ID", 10, (1 - 1) * rows);
		// 构造JSON用的数据结构并返回JSON视图
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("total", units.size());
		result.put("rows", units);
		return new JsonView(result);
	}

	/**
	 * 保存新建涉案物品登记 ,CaseGoods caseGoods
	 */
	public JsonView save(CaseGoods caseGoods) throws Exception {
		String prantid = ((User_list) session.getAttribute("sessionAccount"))
				.getUser_company();
		String userId = ((User_list) session.getAttribute("sessionAccount"))
				.getUser_id() + "";
		String mothed = request.getParameter("method");// 判断是警综操作 还是 新增操作
		String goods_name = request.getParameter("GOODS_NAME");// 物品名称
		String goods_type = request.getParameter("GOODS_TYPE");// 保管物品分类
		String goods_value = request.getParameter("GOODS_VALUES");// 物品价值
		String h_goods_kind = request.getParameter("h_goods_kind");// 保管物品分类
		String h_goods_id = request.getParameter("h_goods_id");// 物品ID

		MultipartFile[] file = ((com.et.mvc.MultipartRequest) request)
				.getFiles("goods_file");

		// 如果是警综过来的那么就不保存CaseGoods表
		if ("modify".equals(mothed)) {
			String conditions = "goods_id=" + h_goods_id;
			caseGoods = caseGoods.findFirst(CaseGoods.class, conditions, null);
			caseGoods.setGoods_id(h_goods_id);
			caseGoods.setKeep_status("1");// 保管中
			updateModel(caseGoods);
			caseGoods.save();
			// 上传图片
			doUpload(h_goods_id, prantid, file[0]);
			// 一般物品属性
			if ("01".equals(h_goods_kind)) {
				String ordinary_brand = request.getParameter("ORDINARY_BRAND");// 物品品牌
				String ordinary_model = request.getParameter("ORDINARY_MODEL");// 物品型号
				String ordinary_num = request.getParameter("ORDINARY_NUM");// 物品数量
				String ordinary_weight = request
						.getParameter("ORDINARY_WEIGHT");// 物品重量
				String ordinary_color = request.getParameter("ORDINARY_COLOR");// 物品颜色
				String ordinary_grain = request.getParameter("ORDINARY_GRAIN");// 物品质地
				String ordinary_fac = request.getParameter("ORDINARY_FAC");// 物品厂牌

				conditions = "";
				conditions = "goods_id=" + h_goods_id;
				Goods_ordinaty go = Goods_ordinaty.findFirst(
						Goods_ordinaty.class, conditions, null);
				if (go == null) { // 如果从表没有记录那么就添加新纪录
					Goods_ordinaty goodsOrd = new Goods_ordinaty();
					goodsOrd.setOrdinary_brand(ordinary_brand);
					goodsOrd.setOrdinary_color(ordinary_color);
					goodsOrd.setOrdinary_fac(ordinary_fac);
					goodsOrd.setOrdinary_grain(ordinary_grain);
					goodsOrd.setOrdinary_model(ordinary_model);
					goodsOrd.setOrdinary_num(ordinary_num);
					goodsOrd.setOrdinary_weight(ordinary_weight);
					goodsOrd.setCreate_date(SysDate.getToday2());
					goodsOrd.setCreate_by(userId);
					goodsOrd.setGoods_id(h_goods_id);
					goodsOrd.save();
				} else {
					go.setOrdinary_brand(ordinary_brand);
					go.setOrdinary_color(ordinary_color);
					go.setOrdinary_fac(ordinary_fac);
					go.setOrdinary_grain(ordinary_grain);
					go.setOrdinary_model(ordinary_model);
					go.setOrdinary_num(ordinary_num);
					go.setOrdinary_weight(ordinary_weight);
					go.setCreate_date(SysDate.getToday2());
					go.setCreate_by(userId);
					updateModel(go);
					go.save();
				}

			} else if ("02".equals(h_goods_kind)) { // 票据类型
				String cash_type = request.getParameter("cash_type");// 票据种类
				String cash_value = request.getParameter("cash_value");// 票据面值
				String cash_num = request.getParameter("cash_num");// 票据张数
				String cash_cost = request.getParameter("cash_cost");// 票据价值

				conditions = "";
				conditions = "goods_id=" + h_goods_id;
				Goods_cash gc = Goods_cash.findFirst(Goods_cash.class,
						conditions, null);
				if (gc == null) { // 如果从表没有记录那么就添加新纪录
					Goods_cash cash = new Goods_cash();
					cash.setCash_cost(cash_cost);
					cash.setCash_num(cash_num);
					cash.setCash_type(cash_type);
					cash.setCash_value(cash_value);
					cash.setCreate_date(SysDate.getToday2());
					cash.setCreate_by(userId);
					cash.setGoods_id(h_goods_id);
					cash.save();
				} else {
					gc.setCash_cost(cash_cost);
					gc.setCash_num(cash_num);
					gc.setCash_type(cash_type);
					gc.setCash_value(cash_value);
					gc.setCreate_date(SysDate.getToday2());
					gc.setCreate_by(userId);
					updateModel(gc);
					gc.save();
				}
			} else if ("05".equals(h_goods_kind)) { // 金银
				String antique_num = request.getParameter("antique_num");// 数量
				String antique_level = request.getParameter("antique_level");// 等级
				String antique_color = request.getParameter("antique_color");// 颜色
				String antique_grain = request.getParameter("antique_grain");// 质地
				conditions = "";
				conditions = "goods_id=" + h_goods_id;
				Goods_antique ga = Goods_antique.findFirst(Goods_antique.class,
						conditions, null);
				if (ga == null) {
					Goods_antique antique = new Goods_antique();
					antique.setAntique_color(antique_color);
					antique.setAntique_grain(antique_grain);
					antique.setAntique_level(antique_level);
					antique.setAntique_num(antique_num);
					antique.setCreate_date(SysDate.getToday2());
					antique.setCreate_by(userId);
					antique.setGoods_id(h_goods_id);
					antique.save();
				} else {
					ga.setAntique_color(antique_color);
					ga.setAntique_grain(antique_grain);
					ga.setAntique_level(antique_level);
					ga.setAntique_num(antique_num);
					ga.setCreate_date(SysDate.getToday2());
					ga.setCreate_by(userId);
					updateModel(ga);
					ga.save();
				}

			} else if ("06".equals(h_goods_kind)) { // 录音 影像
				String video_brief = request.getParameter("video_brief");// 物品案由
				String video_obj = request.getParameter("video_obj");// 物品对象
				String video_content = request.getParameter("video_content");// 物品内容
				String video_type = request.getParameter("video_type");// 物品类别
				String video_mode = request.getParameter("video_mode");// 文件格式
				String video_length = request.getParameter("video_length");// 文件长度
				String video_date = request.getParameter("video_date");// 录制时间
				String video_sub = request.getParameter("video_sub");// 录制地点

				conditions = "";
				conditions = "goods_id=" + h_goods_id;
				Goods_video gv = Goods_video.findFirst(Goods_video.class,
						conditions, null);
				if (gv == null) {
					Goods_video video = new Goods_video();
					video.setVideo_brief(video_brief);
					video.setVideo_content(video_content);
					video.setVideo_date(video_date);
					video.setVideo_length(video_length);
					video.setVideo_mode(video_mode);
					video.setVideo_obj(video_obj);
					video.setVideo_sub(video_sub);
					video.setVideo_type(video_type);
					video.setCreate_date(SysDate.getToday2());
					video.setCreate_by(userId);
					video.setGoods_id(h_goods_id);
					video.save();
				} else {
					gv.setVideo_brief(video_brief);
					gv.setVideo_content(video_content);
					gv.setVideo_date(video_date);
					gv.setVideo_length(video_length);
					gv.setVideo_mode(video_mode);
					gv.setVideo_obj(video_obj);
					gv.setVideo_sub(video_sub);
					gv.setVideo_type(video_type);
					gv.setCreate_date(SysDate.getToday2());
					gv.setCreate_by(userId);
					updateModel(gv);
					gv.save();
				}

			} else if ("07".equals(h_goods_kind)) {// 不动产
				String immovable_ceri = request.getParameter("immovable_ceri");// 登记证书
				String immovable_relatoin = request
						.getParameter("immovable_relatoin");// 权属关系
				String immovable_quate = request
						.getParameter("immovable_quate");// 性质
				String immovable_status = request
						.getParameter("immovable_status");// 状态
				String immovable_validity = request
						.getParameter("immovable_validity");// 有效期
				conditions = "";
				conditions = "goods_id=" + h_goods_id;
				Goods_immovable gi = Goods_immovable.findFirst(
						Goods_immovable.class, conditions, null);
				if (gi == null) {
					Goods_immovable immovable = new Goods_immovable();
					immovable.setImmovable_ceri(immovable_ceri);
					immovable.setImmovable_quate(immovable_quate);
					immovable.setImmovable_relatoin(immovable_relatoin);
					immovable.setImmovable_status(immovable_status);
					immovable.setImmovable_validity(immovable_validity);
					immovable.setCreate_date(SysDate.getToday2());
					immovable.setCreate_by(userId);
					immovable.setGoods_id(h_goods_id);
					immovable.save();
				} else {
					gi.setImmovable_ceri(immovable_ceri);
					gi.setImmovable_quate(immovable_quate);
					gi.setImmovable_relatoin(immovable_relatoin);
					gi.setImmovable_status(immovable_status);
					gi.setImmovable_validity(immovable_validity);
					gi.setCreate_date(SysDate.getToday2());
					gi.setCreate_by(userId);
					updateModel(gi);
					gi.save();
				}
			} else if ("13".equals(h_goods_kind)) {// 汽车类
				String car_no = request.getParameter("car_no");// 车牌号
				String car_type = request.getParameter("car_type");// 号牌种类
				String car_spot = request.getParameter("car_spot");// 识别码
				String car_mileage = request.getParameter("car_mileage");// 行驶里程
				String car_color = request.getParameter("car_color");// 车身颜色
				String car_status = request.getParameter("car_status");// 车辆状况
				String car_owner = request.getParameter("car_owner");// 车主姓名
				String car_idcard = request.getParameter("car_idcard");// 车主身份证号
				conditions = "";
				conditions = "goods_id=" + h_goods_id;
				Goods_car gc = Goods_car.findFirst(Goods_car.class, conditions,
						null);
				if (gc == null) {
					Goods_car car = new Goods_car();
					car.setCar_color(car_color);
					car.setCar_idcard(car_idcard);
					car.setCar_mileage(car_mileage);
					car.setCar_no(car_no);
					car.setCar_spot(car_spot);
					car.setCar_status(car_status);
					car.setCar_type(car_type);
					car.setCar_owner(car_owner);
					car.setCreate_date(SysDate.getToday2());
					car.setCreate_by(userId);
					car.setGoods_id(h_goods_id);
					car.save();
				} else {
					gc.setCar_color(car_color);
					gc.setCar_idcard(car_idcard);
					gc.setCar_mileage(car_mileage);
					gc.setCar_no(car_no);
					gc.setCar_spot(car_spot);
					gc.setCar_status(car_status);
					gc.setCar_type(car_type);
					gc.setCar_owner(car_owner);
					gc.setCreate_date(SysDate.getToday2());
					gc.setCreate_by(userId);
					updateModel(gc);
					gc.save();
				}
			}
		} else {
			// 如果是新增就要保存CaseGoods表
			String goods_values = request.getParameter("GOODS_VALUES");// 物品价值
			String wptz = request.getParameter("WPTZ");// 物品特征描述
			String ajmc = request.getParameter("AJMC");// 案件名称
			String ajlb = request.getParameter("AJLB");// 案件类型
			String ajzt = request.getParameter("AJZT");// 案件状态
			String jyaq = request.getParameter("JYAQ");// 简要案情
			caseGoods.setGoods_name(goods_name);
			caseGoods.setGoods_type(goods_type);
			caseGoods.setGoods_values(goods_values);
			caseGoods.setKeep_status("1");
			String goods_company = CompanyCacheHandler
					.getCompanyCodeById(prantid);
			caseGoods.setGoods_company(goods_company);
			caseGoods.setEnter_date(SysDate.getToday2());
			caseGoods.setSave_date(SysDate.getToday2());
			caseGoods.setOperate_flag("0");
			caseGoods.setGoods_desc(wptz);
			caseGoods.setCase_name(ajmc);
			caseGoods.setCase_type(ajlb);
			caseGoods.setCase_status(ajzt);
			caseGoods.setCase_simple_desc(jyaq);
			if (goods_type != null) {
				caseGoods.setGoods_kind(goods_type.substring(0, 1));
			}
			// caseGoods.setCreate_by(userId);
			caseGoods.save();
			h_goods_id = caseGoods.getGoods_id();
			h_goods_kind = request.getParameter("GOODS_KIND");
			// 上传图片
			doUpload(h_goods_id, prantid, file[0]);
			// 一般物品属性
			if ("01".equals(h_goods_kind)) {
				String ordinary_brand = request.getParameter("ORDINARY_BRAND");// 物品品牌
				String ordinary_model = request.getParameter("ORDINARY_MODEL");// 物品型号
				String ordinary_num = request.getParameter("ORDINARY_NUM");// 物品数量
				String ordinary_weight = request
						.getParameter("ORDINARY_WEIGHT");// 物品重量
				String ordinary_color = request.getParameter("ORDINARY_COLOR");// 物品颜色
				String ordinary_grain = request.getParameter("ORDINARY_GRAIN");// 物品质地
				String ordinary_fac = request.getParameter("ORDINARY_FAC");// 物品厂牌

				Goods_ordinaty goodsOrd = new Goods_ordinaty();
				goodsOrd.setOrdinary_brand(ordinary_brand);
				goodsOrd.setOrdinary_color(ordinary_color);
				goodsOrd.setOrdinary_fac(ordinary_fac);
				goodsOrd.setOrdinary_grain(ordinary_grain);
				goodsOrd.setOrdinary_model(ordinary_model);
				goodsOrd.setOrdinary_num(ordinary_num);
				goodsOrd.setOrdinary_weight(ordinary_weight);
				goodsOrd.setCreate_date(SysDate.getToday2());
				goodsOrd.setCreate_by(userId);
				goodsOrd.setGoods_id(h_goods_id);
				goodsOrd.save();

			} else if ("02".equals(h_goods_kind)) { // 票据类型
				String cash_type = request.getParameter("cash_type");// 票据种类
				String cash_value = request.getParameter("cash_value");// 票据面值
				String cash_num = request.getParameter("cash_num");// 票据张数
				String cash_cost = request.getParameter("cash_cost");// 票据价值

				Goods_cash cash = new Goods_cash();
				cash.setCash_cost(cash_cost);
				cash.setCash_num(cash_num);
				cash.setCash_type(cash_type);
				cash.setCash_value(cash_value);
				cash.setCreate_date(SysDate.getToday2());
				cash.setCreate_by(userId);
				cash.setGoods_id(h_goods_id);
				cash.save();
			} else if ("05".equals(h_goods_kind)) { // 金银
				String antique_num = request.getParameter("antique_num");// 数量
				String antique_level = request.getParameter("antique_level");// 等级
				String antique_color = request.getParameter("antique_color");// 颜色
				String antique_grain = request.getParameter("antique_grain");// 质地
				Goods_antique antique = new Goods_antique();
				antique.setAntique_color(antique_color);
				antique.setAntique_grain(antique_grain);
				antique.setAntique_level(antique_level);
				antique.setAntique_num(antique_num);
				antique.setCreate_date(SysDate.getToday2());
				antique.setCreate_by(userId);
				antique.setGoods_id(h_goods_id);
				antique.save();
			} else if ("06".equals(h_goods_kind)) { // 录音 影像
				String video_brief = request.getParameter("video_brief");// 物品案由
				String video_obj = request.getParameter("video_obj");// 物品对象
				String video_content = request.getParameter("video_content");// 物品内容
				String video_type = request.getParameter("video_type");// 物品类别
				String video_mode = request.getParameter("video_mode");// 文件格式
				String video_length = request.getParameter("video_length");// 文件长度
				String video_date = request.getParameter("video_date");// 录制时间
				String video_sub = request.getParameter("video_sub");// 录制地点

				Goods_video video = new Goods_video();
				video.setVideo_brief(video_brief);
				video.setVideo_content(video_content);
				video.setVideo_date(video_date);
				video.setVideo_length(video_length);
				video.setVideo_mode(video_mode);
				video.setVideo_obj(video_obj);
				video.setVideo_sub(video_sub);
				video.setVideo_type(video_type);
				video.setCreate_date(SysDate.getToday2());
				video.setCreate_by(userId);
				video.setGoods_id(h_goods_id);
				video.save();
			} else if ("07".equals(h_goods_kind)) {// 不动产
				String immovable_ceri = request.getParameter("immovable_ceri");// 登记证书
				String immovable_relatoin = request
						.getParameter("immovable_relatoin");// 权属关系
				String immovable_quate = request
						.getParameter("immovable_quate");// 性质
				String immovable_status = request
						.getParameter("immovable_status");// 状态
				String immovable_validity = request
						.getParameter("immovable_validity");// 有效期
				Goods_immovable immovable = new Goods_immovable();
				immovable.setImmovable_ceri(immovable_ceri);
				immovable.setImmovable_quate(immovable_quate);
				immovable.setImmovable_relatoin(immovable_relatoin);
				immovable.setImmovable_status(immovable_status);
				immovable.setImmovable_validity(immovable_validity);
				immovable.setCreate_date(SysDate.getToday2());
				immovable.setCreate_by(userId);
				immovable.setGoods_id(h_goods_id);
				immovable.save();
			} else if ("13".equals(h_goods_kind)) {// 汽车类
				String car_no = request.getParameter("car_no");// 车牌号
				String car_type = request.getParameter("car_type");// 号牌种类
				String car_spot = request.getParameter("car_spot");// 识别码
				String car_mileage = request.getParameter("car_mileage");// 行驶里程
				String car_color = request.getParameter("car_color");// 车身颜色
				String car_status = request.getParameter("car_status");// 车辆状况
				String car_owner = request.getParameter("car_owner");// 车主姓名
				String car_idcard = request.getParameter("car_idcard");// 车主身份证号
				Goods_car car = new Goods_car();
				car.setCar_color(car_color);
				car.setCar_idcard(car_idcard);
				car.setCar_mileage(car_mileage);
				car.setCar_no(car_no);
				car.setCar_spot(car_spot);
				car.setCar_status(car_status);
				car.setCar_type(car_type);
				car.setCar_owner(car_owner);
				car.setCreate_date(SysDate.getToday2());
				car.setCreate_by(userId);
				car.setGoods_id(h_goods_id);
				car.save();
			}

		}

		JsonView view = new JsonView("success:true");
		view.setContentType("text/html;charset=utf-8");
		// seveSyspriv(new Sys_priv() ,unit);
		return view;
	}

	public void doUpload(String goodsId, String company_id, MultipartFile file) {
		String rootPath = request.getParameter("rootPath");
		String path = request.getParameter("path");
		if (rootPath == null)
			rootPath = "";
		rootPath = rootPath.trim();
		if (rootPath.equals("")) {
			rootPath = getServletContext().getRealPath("/swfupload/files/");
		}
		if (path == null) {
			path = rootPath;
		}
		// DiskFileItemFactory factory = new DiskFileItemFactory();
		// factory.setSizeThreshold(1024000);// 指定在内存中缓存数据大小,单位为byte
		// ServletFileUpload upload = new ServletFileUpload(factory);
		// upload.setFileSizeMax(5000000);// 指定单个上传文件的最大尺寸(单个文件大小不超过5M)
		// upload.setSizeMax(20000000);// 指定一次上传多个文件的总尺寸(总文件大小不超过20M)
		try {
			if(file!=null && file.getSize()>0){
				String fileName = file.getOriginalFilename();
				// 获取上传文件后缀
				String suff = fileName.substring(fileName.lastIndexOf("."));
				// 以当前精确到秒的日期为上传的文件的文件名
				SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss");
				String imgName = goodsId + "_" + sdf.format(new Date()) + suff;
				file.transferTo(new File(path, imgName));
				Case_goods_img cgi = new Case_goods_img();
				cgi.setImg_id(goodsId); // 物品编号
				cgi.setImp_code(imgName); // 图片名称
				cgi.setImg_pages(path + "\\" + imgName);
				cgi.setImg_enter_date(SysDate.getToday2());
				cgi.setImg_enter_company(company_id);
				cgi.save();
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
